package cn.edu.sjtu.todo.nodes;

import java.util.LinkedList;
import java.util.List;

public class MethodNode {
	
	protected String methodName;	// full name
	
	protected String className;
	
	protected StringBuffer code;
	
	protected long filePos;
	
	protected long lineNum;
	
	protected List<String> inMethods;
	
	protected List<String> outMethods;
	
	private MethodNode(String mn, String cn, String c, long fp, long ln) {
		methodName = mn;
		className = cn;
		code = new StringBuffer(c);
		filePos = fp;
		lineNum = ln;
		inMethods = new LinkedList<String>();
		outMethods = new LinkedList<String>();
	}

	public static MethodNode createMethodNode(String mn, String cn, String c, long fp, long ln) {
		/*MethodNode n = getMethodNode(mn);
		if (n == null) {
			n = new MethodNode(mn, cn, c, fp, ln);
		} else {
			if (n.getCode().equals("")) {
				n.setCode(c);
			}
			if (n.getFilePos() == -1) {
				n.setFilePos(fp);
			}
			if (n.getLineNum() == -1) {
				n.setLineNum(ln);
			}
		}*/
		return new MethodNode(mn, cn, c, fp, ln);
	}
	
	public void addInMethod(String m) {
		inMethods.add(m);
	}
	
	public void addOutMethod(String m) {
		outMethods.add(m);
	}
	
	public void addCode(String c) {
		code.append(c);
	}
	
	public void setCode(String c) {
		code = new StringBuffer(c);
	}
	
	public List<String> getInMethods() {
		return inMethods;
	}
	
	public List<String> getOutMethods() {
		return outMethods;
	}
	
	public String getMethodName() {
		return methodName;
	}

	public void setClassName(String c) {
		className = c;
	}
	
	public String getClassName() {
		return className;
	}

	public String getCode() {
		return code.toString();
	}

	public void setFilePos(long fp) {
		filePos = fp;
	}
	
	public long getFilePos() {
		return filePos;
	}

	public void setLineNum(long ln) {
		lineNum = ln;
	}
	
	public long getLineNum() {
		return lineNum;
	}
}
